<template>
  <BaseMainSlot>
    <template v-slot:btn-box>
      <ActionBar :page-no="78" :add-active="addActive" :del-active="delActive" :edit-active="editActive" :has-add="false"
        :has-edit="false" @add="add" @edit="edit" @del="del" />
    </template>
    <template v-slot:search-box>
      <el-collapse v-model="activeName" accordion @change="handleChange">
        <el-collapse-item name="1">
          <template slot="title">
            <div class="select-btns search-btns" @click.stop="changeSelect()">
              <i class="el-icon-circle-check"></i>
              <p v-if="activeName === '1'">收起筛选</p>
              <p v-if="activeName === ''">展开筛选</p>
            </div>
          </template>
          <div class="search-btn search-btns" @click.stop="search()">
            <i class="el-icon-circle-check"></i>
            <p>查询</p>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">检验名称</div>
            <el-input v-model="recordCode" placeholder="请输入码单号" clearable @input="search" />
          </div>
        </el-collapse-item>
      </el-collapse>
    </template>
    <template v-slot:table-box>
      <el-table ref="tableData" v-loading="loading" :data="tableData" stripe border height="88%"
        @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" :selectable="(row) => { return !row.selectable }" />
        <el-table-column type="index" label="序号" width="50" />
        <el-table-column prop="recordCode" label="码单号" />
        <el-table-column prop="checkNum" label="检验条数" />
        <el-table-column prop="checkTotalWeight" label="总重" />
        <el-table-column prop="supplierName" label="供应商" />
        <el-table-column prop="checkTotalWeight" label="检验人" />
        <el-table-column label="操作" width="200">
          <template v-if="scope.row.checkRecordId" slot-scope="scope">
            <el-button class="text-btn-cursor" type="text" v-if="judgePermission(79, 'edit')" size="small"
              @click="completeInfo(scope.row)">
              <i class="el-icon-edit-outline"></i> 查看详情
            </el-button>
            <el-button class="text-btn-cursor cursor-delete" type="text" size="small" v-if="judgePermission(79, 'delete')"
              @click="handleDelete(scope.row)">
              <i class="el-icon-delete"></i> 删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <Pagination :page-size="pageSize" :current-page="currentPage" :total-size="totalSize"
        @changePageSize="changePageSize" @changeCurrentPage="changeCurrentPage" />
    </template>
    <template v-slot:dialog>
      <CompleteInfoDialog ref="addEditDialog" :now-chance-stau="nowChanceStau" :complete-info-object="completeInfoObject"
        :show.sync="showCompleteInfoDialog" @closeDialog="closeDialog" @cancelDialog="cancel" />
    </template>
  </BaseMainSlot>
</template>

<script>
import ActionBar from "@/components/ActionBar";
import Pagination from "@/components/Pagination";
import InspectionRecordApi from "@/api/inspection-management/inspection-record";
import CompleteInfoDialog from "./components/complete-info-dialog.vue";
import BaseMainSlot from "@/components/BaseMainSlot/newBaseMainSlot";
import { mymixin } from "@/utils/mixins";
import { mapGetters } from "vuex";
export default {
  name: "InspectionRecord",
  components: {
    ActionBar,
    Pagination,
    BaseMainSlot,
    CompleteInfoDialog
  },
  mixins: [mymixin],
  data() {
    return {
      // 码单号
      recordCode: "",
      completeInfoObject: {},
      rules: {
        checkTypeName: [
          { required: true, message: "请输入巡查点名称", trigger: "blur" }
        ],
        errorRange: [
          { required: true, message: "请输入误差范围值(米)", trigger: "blur" }
        ],
        longitude: [
          { required: true, message: "请在下方选择巡查点", trigger: "blur" }
        ],
        latitude: [
          { required: true, message: "请在下方选择巡查点或者输入经纬度", trigger: "change" }
        ]
      },
      showCompleteInfoDialog: false,
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission"
    })
  },
  watch: {
    // 动态添加数据
    formData: {
      deep: true,
      handler(val) {
        if (val.latitude || val.longitude) {
          this.center = {
            lng: val.longitude,
            lat: val.latitude
          };
        }
      }
    }
  },
  created() { },
  mounted() {
    this.search();
  },
  methods: {
    getTableDataList() {
      this.loading = true;
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        entity: {
          recordCode: this.recordCode || undefined
        }
      };
      InspectionRecordApi.queryPageByCondition(params).then(res => {
        this.loading = false;
        let data = res.data;
        // 赋值总条数
        if (data) {
          this.totalSize = data.totalElements;
          this.tableData = data.content;
          this.addblankmet();
          this.resetActionBar();
        }
      });
    },
    // 点击详情
    completeInfo(row) {
      // console.log(row);
      if (row.checkRecordId) {
        this.completeInfoObject = JSON.parse(JSON.stringify(row));
        this.showCompleteInfoDialog = true;
      }
    },
    handleSelectionChange(list) {
      this.inspectionPointIdList = [];
      this.inspectionPointIdList = list.map(item => item.checkRecordId);
      if (this.inspectionPointIdList.length > 0) this.delActive = true;
      else this.delActive = false;
    },
    delmessage() {
      InspectionRecordApi.delListById({
        idList: [this.inspectionPointIdList]
      }).then(res => {
        if (res.success) {
          this.search();
          this.$message.success(res.message || "删除成功");
          this.facilityList = [];
          this.nowfishPondId = "";
        } else {
          this.$message.warning(res.message || "删除失败");
        }
      });
    },
    handleDelete(row) {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        
      })
        .then(() => {
          InspectionRecordApi.delById({ id: row.checkRecordId }).then(res => {
            if (res.success) {
              this.resetActionBar()
              this.search();
              this.$message.success(res.message || "删除成功");
            } else {
              this.$message.warning(res.message || "删除失败");
            }
          });
        })
        .catch(() => {
          this.resetActionBar()
          this.$message("取消删除");
        });
    },
    // 取消
    cancel() {
      this.nowChanceStau = '';
      this.titleText = ''
      this.editObject = {}
      this.showAddEditDialog = false
      this.showCompleteInfoDialog = false;
      this.resetActionBar()
    },
  }
};
</script>

<style scoped lang="scss">
@import "~@/styles/variables.scss";

::v-deep .content {
  .table-box {
    width: 50% !important;
  }

  .form {
    width: 48% !important;
    position: relative;
    overflow: hidden;
  }
}

::v-deep .lng {
  .el-form-item__content {
    >span {
      width: 100%;
    }
  }

  .el-input__inner {
    min-width: 90px;
  }
}

::v-deep .lat {
  .el-form-item__content {
    >span {
      width: 100%;
    }
  }

  .el-form-item__label {
    text-align: end;
    min-width: 100px !important;
  }
}

::v-deep .dialog {
  .el-dialog__headerbtn {
    top: 0;
    right: 10px;
  }
}
</style>
